/**
 * @file processBar.c
 * @author xzq
 * @brief 
 * @version 0.1
 * @date 2024-10-26
 * 
 * @copyright Copyright (c) 2024
 * 
 */
#include "string.h"
#include "stdio.h"
#include "processBar.h"

void downloadProcessBar(char *bar,unsigned int current,unsigned int total)
{
    char bar_label[5] = "|/-\\";
    char bar_process[101] = {0};
    int label_len = strlen(bar_label);
    int count = 0;

    double rate = (100.0 * current) / (total * 1.0);
    int cycle = (int )rate;

    for(;count < cycle;)
    {
        bar_process[count ++] = '#';
    }
    sprintf(bar,"[%-100s][%d/%d][%.1lf%%][%c]\r",bar_process,current,total,rate,bar_label[count % label_len]);
}
